package com.telit.firecommand.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.telit.common.util.*;
import com.telit.firecommand.config.properties.FireProperties;
import com.telit.firecommand.constant.DBWConstant;
import com.telit.firecommand.constant.RedisKeyConstant;
import com.telit.firecommand.dao.*;
import com.telit.firecommand.dto.GeoCunDTO;
import com.telit.firecommand.entity.CommCameraInfo;
import com.telit.firecommand.entity.CommFireAlarm;
import com.telit.firecommand.facade.FireTriggerFacadeService;
import com.telit.firecommand.model.camera.ThirdPushFireMediaModel;
import com.telit.firecommand.model.camera.ThirdPushFireModel;
import com.telit.firecommand.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 火情信息service
 *
 * @author chencf
 * @date 2022-09-19
 */
@Slf4j
@Service
public class FireAlarmsServiceImpl implements FireAlarmsService {

    @Value("${fire.haikang.picAdress}")
    private String hikPicAdress;

    @Value("${fire.downloadImgFolder}")
    private String downloadImgFolder;

    @Autowired
    private FireAlarmsDao fireAlarmsDao;
    @Autowired
    private CommFireAlarmDao commFireAlarmDao;

    @Autowired
    private SysOperationLogDAO sysOperationLogDAO;

    @Autowired
    private FireQueryDao fireQueryDao;

    @Autowired
    private GeoXzqhCunDao geoXzqhCunDao;


    @Autowired
    private CameraInfoService cameraInfoService;

    @Autowired
    private SmsService smsService;

    @Autowired
    private MsgPushReceiverService msgPushReceiverService;

    @Autowired
    private SysUserDAO sysUserDAO;

    @Autowired
    private CommMsgCenterLogService commMsgCenterLogService;

    @Autowired
    private FireTriggerFacadeService fireTriggerFacadeService;

    @Autowired
    private FireProperties fireProperties;

    @Autowired
    private RestTemplate restTemplate;


//    /**
//     * 火情上报
//     *
//     * @param commFireAlarmDTO
//     *
//     * @return FireAlarmsDTO
//     */
//    @Override
//    public String save(CommFireAlarmDTO commFireAlarmDTO) {
//        CommFireAlarm commFireAlarm = new CommFireAlarm();
//        BeanUtils.copyProperties(commFireAlarmDTO, commFireAlarm);
//        commFireAlarm.setIsRead(2);
//        commFireAlarm.setIsRescue(2);
//        commFireAlarmDao.insertSelective(commFireAlarm);
//        return commFireAlarm.getId();
//    }

    //    /**
//     * 护林员上报
//     *
//     * @param commFireAlarmDTO
//     *
//     * @return FireAlarmsDTO
//     */
//    @Override
//    public String foresterSave(CommFireAlarmDTO commFireAlarmDTO) {
//        CommFireAlarm commFireAlarm = new CommFireAlarm();
//        BeanUtils.copyProperties(commFireAlarmDTO, commFireAlarm);
//        commFireAlarm.setId(UUID.randomUUID().toString());
//        commFireAlarm.setIsRead(1);
//        commFireAlarm.setFireJudgmentType(1);
//        commFireAlarm.setFindTime(new Date());
//        commFireAlarm.setStatus(1);
//        commFireAlarm.setIsRescue(2);
//        commFireAlarmDao.insertSelective(commFireAlarm);
//        String fireId = commFireAlarm.getId();
//        //推送socker消息
//        PushSocketDTO pushSocketDTO = new PushSocketDTO();
//        pushSocketDTO.setFireId(fireId);
//        pushSocketDTO.setLongitude(commFireAlarm.getLongitude());
//        pushSocketDTO.setLatitude(commFireAlarm.getLatitude());
//        pushSocketDTO.setAreaCode(commFireAlarm.getDistrictCode());
//        pushSocketDTO.setStatus(1);
//        smsService.pushSocket(pushSocketDTO);
//        return commFireAlarm.getId();
//    }
//
//
//    /**
//     * 火情卫星上报
//     *
//     * @param addFireBySatelliteRequest FireAlarmsInsertRequest
//     *
//     * @return FireAlarmsDTO
//     */
//    @Override
//    public FireAlarmsDTO saveBySatellite(AddFireBySatelliteRequest addFireBySatelliteRequest) {
//        if (addFireBySatelliteRequest.getHotId() == null || addFireBySatelliteRequest.getHotId().compareTo(0L) == 0) {
//            addFireBySatelliteRequest.setHotId(Math.abs(new Random().nextLong()));
//        }
//
//        //传递给赛达时间戳
//        Map<String, Object> map = JSON.parseObject(JSON.toJSONString(addFireBySatelliteRequest), Map.class);
//        map.put("receiveTime", addFireBySatelliteRequest.getReceiveTime().getTime());
//        map.put("satelliteReportTime", addFireBySatelliteRequest.getSatelliteReportTime().getTime());
//        SaidaAddFireBySatelliteRequest saidaAddFireBySatelliteRequest = JSON.parseObject(JSON.toJSONString(map),
//                SaidaAddFireBySatelliteRequest.class);
//        DataReturn dataReturn = alarmsFeignClient.saveBySatellite(saidaAddFireBySatelliteRequest);
//        if (!ResultCode.SUCCESS.getCode().equals(dataReturn.getCode())
//                && !FireConstant.ALARMS_SUCCESS_CODE.equals(dataReturn.getCode())) {
//            throw new ForestBaseException(dataReturn.getErrorMsg());
//        }
//
//        FireAlarmsDTO fireAlarmsDTO = JSON.parseObject(JSON.toJSONString(dataReturn.getData()), FireAlarmsDTO.class);
//        //添加此处逻辑是为了提示报警音
////        if (Objects.nonNull(fireAlarmsDTO)&&fireAlarmsDTO.getStatus()==1) {
////            jobService.insertTask(fireAlarmsDTO.getId(), fireAlarmsDTO.getAreaCode(),fireAlarmsDTO.getStartTime());
////        }
//        return fireAlarmsDTO;
//    }
//
//
//    @Override
//    public Boolean isRescue(String fireId) {
//        Boolean flag = false;
//        Integer isRescue = fireQueryDao.findIsRescue(fireId);
//        if (isRescue == 0) {
//            flag = true;
//        }
//        return flag;
//    }
//
//
//    @Override
//    public FireFeignAlarmsVO fireInfoByFireId(String fireId) {
//        DataReturn dataReturn = alarmsFeignClient.qryAlarmsInfo(fireId);
//        if (!ResultCode.SUCCESS.getCode().equals(dataReturn.getCode())
//                && !FireConstant.ALARMS_SUCCESS_CODE.equals(dataReturn.getCode())) {
//            throw new ForestBaseException(dataReturn.getErrorMsg());
//        }
//        FireFeignAlarmsVO fireFeignAlarmsVO = JSON.parseObject(JSON.toJSONString(dataReturn.getData()),
//                FireFeignAlarmsVO.class);
//        return fireFeignAlarmsVO;
//    }
//
//    @Override
//    public void isTruefire(FireAlarmsUpdateStatusRequest fireAlarmsUpdateStatusRequest) {
//        DataReturn dataReturn = alarmsFeignClient.isTruefire(fireAlarmsUpdateStatusRequest);
//        if (!ResultCode.SUCCESS.getCode().equals(dataReturn.getCode())
//                && !FireConstant.ALARMS_SUCCESS_CODE.equals(dataReturn.getCode())) {
//            throw new ForestBaseException(dataReturn.getErrorMsg());
//        }
//        return;
//    }
//
//    @Override
//    public void updateStatus(FireAlarmsUpdateStatusDTO fireAlarmsUpdateStatusDTO) {
//        //火情接警
//        //step 1 直接修改状态  从1-->2的状态
//        fireAlarmsDao.updateFireStatus(fireAlarmsUpdateStatusDTO.getStatus(), new Date(), null, null, null,
//                fireAlarmsUpdateStatusDTO.getFireId());
//    }
//
//    @Override
//    public void confirmAlarm(ConfirmAlarmDTO confirmAlarmDTO) {
//        fireAlarmsDao.updateFireStatus(3, null, new Date(), null, confirmAlarmDTO.getIsTrue(),
//                confirmAlarmDTO.getFireId());
//    }
//
//    //确认非火情
//    @Override
//    public void conUnfirmAlarm(ConfirmAlarmDTO confirmAlarmDTO) {
//        fireAlarmsDao.updateFireStatus(4, null, new Date(), null, confirmAlarmDTO.getIsTrue(),
//                confirmAlarmDTO.getFireId());
//    }
//
//    //重复火情
//    @Override
//    @Transactional
//    public void alarmsRepeat(AlarmsRepeatDTO alarmsRepeatDTO) {
//        //重复火情合并规则：确认为重复火情后，火情告警信息不展示；火情操作状态与合并的火情状态一致；
//        //将当前火情改成不显示  改成重复火情状态
//        fireAlarmsDao.updateAlarmsRepeat(alarmsRepeatDTO.getAlarmsId(), alarmsRepeatDTO.getRepeatIdStatus(), 1);
//
//        //将重复火情的合并源id改成当前火情
//        fireAlarmsDao.updateOriginFireId(alarmsRepeatDTO.getAlarmsId(), alarmsRepeatDTO.getRepeatId());
//    }
//
//    @Override
//    public void beginRescue(AlarmsRescueDTO alarmsRescueDTO) {
//        //开始扑救
//        fireAlarmsDao.beginRescue(alarmsRescueDTO.getFireId());
//    }
//
//    //抢险救援扑救
//    @Override
//    public void endRescue(AlarmsRescueDTO alarmsRescueDTO) {
//        //完成扑救
//        fireAlarmsDao.endRescue(alarmsRescueDTO.getFireId());
//    }
//
//
//    @Override
//    public void firePosition(FirePositionDTO firePositionDTO) {
//        firePositionDTO.setId(firePositionDTO.getFireId());
//        //修改经纬度
//        fireAlarmsDao.updatePosition(firePositionDTO);
//
//    }
//
//    @Override
//    public List<OperationVO> fireOperatorLog(String fireId) {
//        List<OperationVO> result = new ArrayList<>();
//        //查询为接警的status=1
//        // OperationVO bj = sysOperationLogDAO.fireOperatorLogJj(fireId, FireStatusStatus.ONE.getCode(), BusinessOperatorType.JJBJ.getCode());
//        OperationVO bj = new OperationVO();
//        // if (Objects.nonNull(bj)) {
//        bj.setStatus(1);
//        bj.setStatusName(FireStatusStatus.code2Str(bj.getStatus()));
//        List<OperationDetailVO> operationDetailVOSOne = sysOperationLogDAO.fireOperatorDetailLog(fireId,
//                FireStatusStatus.ONE.getCode());
//        for (OperationDetailVO operationDetailVO : operationDetailVOSOne) {
//            if (StringUtils.isBlank(operationDetailVO.getBusinessOperatorTypeName())) {
//                operationDetailVO.setBusinessOperatorTypeName(
//                        BusinessOperatorType.code2Str(operationDetailVO.getBusinessOperatorType()));
//            }
//        }
//        bj.setOperationDetailVOList(operationDetailVOSOne);
//        result.add(bj);
//        //}
//
//        //查询待研判的 status=2
////        OperationVO yp = sysOperationLogDAO.fireOperatorLogJj(fireId, FireStatusStatus.TWO.getCode(), BusinessOperatorType.QRHQ.getCode());
//        OperationVO yp = new OperationVO();
//        //  if (Objects.nonNull(yp)) {
//        //  yp.setStatusName(FireStatusStatus.code2Str(yp.getStatus()));
//        yp.setStatus(2);
//        yp.setStatusName(FireStatusStatus.code2Str(yp.getStatus()));
//        //查询在2状态下面操作记录
//        List<OperationDetailVO> operationDetailVOSTwo = sysOperationLogDAO.fireOperatorDetailLog(fireId,
//                FireStatusStatus.TWO.getCode());
//        //排除25
//        //operationDetailVOSTwo = operationDetailVOSTwo.stream().filter(v -> !v.getBusinessOperatorType().equals(25)).collect(Collectors.toList());
//        for (OperationDetailVO operationDetailVO : operationDetailVOSTwo) {
//            if (StringUtils.isBlank(operationDetailVO.getBusinessOperatorTypeName())) {
//                operationDetailVO.setBusinessOperatorTypeName(
//                        BusinessOperatorType.code2Str(operationDetailVO.getBusinessOperatorType()));
//            }
//        }
//        yp.setOperationDetailVOList(operationDetailVOSTwo);
//        result.add(yp);
//        // }
//
//
//        //status=3
//        // OperationVO cz = sysOperationLogDAO.fireOperatorLogJj(fireId, FireStatusStatus.THREE.getCode(), BusinessOperatorType.WCCZ.getCode());
//        OperationVO cz = new OperationVO();
//        // if (Objects.nonNull(cz)) {
//        cz.setStatus(3);
//        cz.setStatusName(FireStatusStatus.code2Str(cz.getStatus()));
//        List<OperationDetailVO> operationDetailVOSThree = sysOperationLogDAO.fireOperatorDetailLog(fireId,
//                FireStatusStatus.THREE.getCode());
//        //排除34
//        // operationDetailVOSThree = operationDetailVOSThree.stream().filter(v -> !v.getBusinessOperatorType().equals(34)).collect(Collectors.toList());
//        for (OperationDetailVO operationDetailVO : operationDetailVOSThree) {
//            if (StringUtils.isBlank(operationDetailVO.getBusinessOperatorTypeName())) {
//                operationDetailVO.setBusinessOperatorTypeName(
//                        BusinessOperatorType.code2Str(operationDetailVO.getBusinessOperatorType()));
//            }
//        }
//        cz.setOperationDetailVOList(operationDetailVOSThree);
//        result.add(cz);
//        //   }
//
//        //status=3
//        // OperationVO cz = sysOperationLogDAO.fireOperatorLogJj(fireId, FireStatusStatus.THREE.getCode(), BusinessOperatorType.WCCZ.getCode());
//        OperationVO wc = new OperationVO();
//        // if (Objects.nonNull(cz)) {
//        wc.setStatus(4);
//        wc.setStatusName(FireStatusStatus.code2Str(wc.getStatus()));
//        List<OperationDetailVO> operationDetailVOSFour = sysOperationLogDAO.fireOperatorDetailLog(fireId,
//                FireStatusStatus.FOUR.getCode());
//        //排除34
//        // operationDetailVOSThree = operationDetailVOSThree.stream().filter(v -> !v.getBusinessOperatorType().equals(34)).collect(Collectors.toList());
//        for (OperationDetailVO operationDetailVO : operationDetailVOSFour) {
//            if (StringUtils.isBlank(operationDetailVO.getBusinessOperatorTypeName())) {
//                operationDetailVO.setBusinessOperatorTypeName("火烧迹地");
//            }
//        }
//        wc.setOperationDetailVOList(operationDetailVOSFour);
//        result.add(wc);
//
//
//        return result;
//    }
//
//
//    @Override
//    public List<FireQueryAllListVO> repeatAlarmsList(String fireId, String longitude, String latitude) {
//        List<FireQueryAllListVO> result = new ArrayList<>();
//        //查询全部的真实火情
//        List<FireQueryAllListVO> allTrueFire = fireQueryDao.findAllTrueFire();
//        for (FireQueryAllListVO fireQueryAllListVO : allTrueFire) {
//            //根据行政区划代码查询地址
//            if (fireQueryAllListVO.getDistrictCode() != null) {
//                fireQueryAllListVO.setDistrictCodeName(
//                        geoXzqhCunDao.queryNameByCode(fireQueryAllListVO.getDistrictCode(),
//                                fireQueryAllListVO.getDistrictCode().length()));
//            }
//            if (StringUtils.isNotBlank(fireQueryAllListVO.getSourceType())) {
//                fireQueryAllListVO.setSourceTypeName(
//                        FireSourceTypeStatus.code2Str(Integer.parseInt(fireQueryAllListVO.getSourceType())));
//            }
//            //判断是否在2km内容
//
//            double longitudeT = Double.parseDouble(fireQueryAllListVO.getLongitude());
//            double latitudeT = Double.parseDouble(fireQueryAllListVO.getLatitude());
//            double distance = GeoUtils.GetDistanceTwo(Double.parseDouble(longitude), Double.parseDouble(latitude),
//                    longitudeT, latitudeT);
//            //  if (distance <= Double.parseDouble("2")) {
//            result.add(fireQueryAllListVO);
//            //}
//
//
//        }
//        return result;
//    }
//
//    @Override
//    public void isReadFire(String fireId, Integer isWatchman) {
//        fireAlarmsDao.isReadFire(fireId, isWatchman);
//    }
//
    @Override
    public synchronized  void addFireByCamera(String data) {
        JSONObject rcvBodyJson = JSONObject.parseObject(String.valueOf(data));
        String type = rcvBodyJson.getString("type");
        if (StrUtil.equals("fire", type)) {//火情
            ThirdPushFireModel thirdPushFireModel = JSON.parseObject(rcvBodyJson.getString("data"),
                    ThirdPushFireModel.class);
            String cameraIndexCode = thirdPushFireModel.getChannelId();
            CommCameraInfo commCameraInfo = cameraInfoService.queryByCameraIndexCode(cameraIndexCode);
            if (commCameraInfo == null) {
                log.info("监控cameraIndexCode=" + cameraIndexCode + "未找到对应信息");
                return;
            }

            CommFireAlarm commFireAlarm = new CommFireAlarm();
            commFireAlarm.setThirdId(thirdPushFireModel.getId());
            commFireAlarm.setAction("1");
            commFireAlarm.setResource("3");
            commFireAlarm.setStatus("1");
            commFireAlarm.setFindTime(
                    DateUtil.parse(thirdPushFireModel.getDatetime(), DatePattern.NORM_DATETIME_PATTERN));
            GeoCunDTO geoCunDTO = geoXzqhCunDao.getDistrictByPoint(thirdPushFireModel.getTargetLongitude().toString(),
                    thirdPushFireModel.getTargetLatitude().toString());
            if (geoCunDTO != null) {
                commFireAlarm.setDistrictCode(geoCunDTO.getXiang());
            }
            commFireAlarm.setFireJudgmentType(1);
            String regionName = TiandituUtlis.getDetailAddress(thirdPushFireModel.getTargetLongitude().toString(),
                    thirdPushFireModel.getTargetLatitude().toString());
            commFireAlarm.setContent(commCameraInfo.getName() + "-监控发现" + regionName + "发生疑似火情");
            commFireAlarm.setDetailAddress(regionName);
            commFireAlarm.setLongitude(thirdPushFireModel.getTargetLongitude().toString());
            commFireAlarm.setLatitude(thirdPushFireModel.getTargetLatitude().toString());
            commFireAlarm.setDeviceId(commCameraInfo.getId());
            commFireAlarm.setFinderName(commCameraInfo.getName() + "监控");
            commFireAlarm.setDeviceId(commCameraInfo.getId());
            commFireAlarm.setDeviceName(commCameraInfo.getName());
            commFireAlarm.setCountryside(commCameraInfo.getCountryside());
            commFireAlarm.setDetailAddress(regionName);

            List<ThirdPushFireModel.Attachment> attachments = thirdPushFireModel.getAttachments();
            List<String> fileList = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(attachments)) {
                attachments.forEach(attachment -> {
                    String fileName = attachment.getId() + "." + attachment.getExt();
                    InputStream inputStream = download(attachment.getId());
                    if (inputStream != null) {
                        String fileUrl = OssUtils.upload(fileName, fileName,
                                MediaType.APPLICATION_OCTET_STREAM.toString(), inputStream, null);
                        fileList.add(fileUrl);
                    }
                });
            }
            if (CollectionUtil.isNotEmpty(fileList)) {
                commFireAlarm.setImageUrl(JSON.toJSONString(fileList));
            }

            //火情先保留原始数据，然后做时间和半径过滤
            commFireAlarmDao.insertPrimal(commFireAlarm);

            //是否开启过滤
//            String filterSwitch=RedisUtils.get(RedisKeyConstant.FILTER_SWITCH);
//            if(StrUtil.isNotEmpty(filterSwitch) && StrUtil.equals("1", filterSwitch)){//开启了过滤则进行过滤
//                boolean sameFire=verifySameFire(CollUtil.newArrayList("3", "4", "5", "8", "9"), commFireAlarm.getLongitude(), commFireAlarm.getLatitude(), commFireAlarm.getFindTime());
//                if(!sameFire){
//                    fireTriggerFacadeService.addFire(commFireAlarm, null);
//                }
//            }else{
//                fireTriggerFacadeService.addFire(commFireAlarm, null);
//            }
            boolean sameFire=verifySameFire(CollUtil.newArrayList("3", "4", "5", "8", "9"), commFireAlarm.getLongitude(), commFireAlarm.getLatitude(), commFireAlarm.getFindTime());
            if(!sameFire){
                fireTriggerFacadeService.addFire(commFireAlarm, null);
            }


        } else if (StrUtil.equals("record", type)) {//火情对应的媒体信息
            ThirdPushFireMediaModel thirdPushFireMediaModel = JSON.parseObject(rcvBodyJson.getString("data"),
                    ThirdPushFireMediaModel.class);
            String thirdId = thirdPushFireMediaModel.getEventId();
            String attachmentId = thirdPushFireMediaModel.getAttachmentId();
            String ext = thirdPushFireMediaModel.getExt();
            CommFireAlarm commFireAlarm = commFireAlarmDao.selectByThirdId(thirdId);
            if (commFireAlarm == null) {
                return;
            }
            List<String> fileList = new ArrayList<>();
            String imageUrl = commFireAlarm.getImageUrl();
            if (StrUtil.isNotEmpty(imageUrl)) {
                fileList = JSON.parseArray(imageUrl, String.class);
            }
            String fileName = attachmentId + "." + ext;
            InputStream inputStream = download(attachmentId);
            if (inputStream != null) {
                String fileUrl = OssUtils.upload(fileName, fileName,
                        MediaType.APPLICATION_OCTET_STREAM.toString(), inputStream, null);
                fileList.add(fileUrl);
            }
            if (CollectionUtil.isNotEmpty(fileList)) {
                commFireAlarm.setImageUrl(JSON.toJSONString(fileList));
                commFireAlarmDao.updateByPrimaryKeySelective(commFireAlarm);
            }
        }

    }

    /**
     * 第三方火情附件下载
     *
     * @param id id
     *
     * @return InputStream
     */
    @Override
    public InputStream download(String id) {
        String url = fireProperties.getDbw().getApiUrl() + DBWConstant.DOWNLOAD_URL;
        String token = fireProperties.getDbw().getToken();
        String param = "?token=" + token + "&id=" + id;
        ResponseEntity<Resource> entity = restTemplate.getForEntity(url + param, Resource.class);
        try {
            return entity.getBody().getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * *规则：同一来源1公里内，1小时内重复报警（3月25日为了推进验收规则改成500米，10分钟,3月29日改成15分钟）
     * @param resource
     * @param longitude
     * @param latitude
     * @param findTime
     * @return
     */
    private boolean verifySameFire(List<String> resource, String longitude, String latitude, Date findTime) {
        //校验逻辑
        //相同来源火情校验
        List<CommFireAlarm> list = commFireAlarmDao.querySameSourceUnCompleteDisposalFire(resource);
        if (list != null && list.size() != 0) {
            List<CommFireAlarm> unCompleteDisposalFire = list.stream()
                    .filter(
                            e -> {
                                double distanceMeter = GeoUtils.GetDistanceTwo(Double.parseDouble(longitude), Double.parseDouble(latitude), Double.parseDouble(e.getLongitude()), Double.parseDouble(e.getLatitude()));
                                return distanceMeter <= 0.5;
                            }

                    ).collect(Collectors.toList());
            //过滤一小时内重复（3月25日为了推进验收规则改成500米，10分钟）
            unCompleteDisposalFire = unCompleteDisposalFire.stream().filter(e ->  TimeUtils.compareDate(TimeUtils.dateStr(e.getFindTime()),TimeUtils.dateStr(findTime)) < 0.25).collect(Collectors.toList());
            if (unCompleteDisposalFire.size() != 0) {
                //有相同来源数据
                return true;
//                throw new ForestBaseException(ResultCode.OPERATE_ERROR.getCode(), "该火情已有上报记录！");
            }
        }
        //不同来源火情校验
        list = commFireAlarmDao.queryNotSameSourceUnCompleteDisposalFire(resource);
        if (list != null && list.size() != 0) {
            List<CommFireAlarm> unCompleteDisposalFire = list.stream().filter(
                    e -> {
                        double distanceMeter = GeoUtils.GetDistanceTwo(Double.parseDouble(longitude), Double.parseDouble(latitude), Double.parseDouble(e.getLongitude()), Double.parseDouble(e.getLatitude()));
                        return distanceMeter <=1;
                    }
            ).collect(Collectors.toList());
            Set<String> set = new HashSet<>(list.size());
            if (unCompleteDisposalFire.size() > 1) {
                unCompleteDisposalFire.forEach(a -> {
                    String source = a.getResource();
                    set.add(source);
                });
            }
            if (set.size() > 2) {
                //来源已有2个，不允许新增
                return true;
//                throw new ForestBaseException(ResultCode.OPERATE_ERROR.getCode(), "该火情已有上报记录！");
            } else {
                //来源只有1个，可以新增
            }
        }
        return false;
    }

}
